package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.BusShop;
import com.ruoyi.business.service.IBusShopService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 药品Controller
 *
 * @author lzq
 * @date 2022-10-22
 */
@Api(tags = "药品信息管理")
@RestController
@RequestMapping("/api/business/shop")
public class BusShopController extends BaseController {
    @Autowired
    private IBusShopService busShopService;

    /**
     * 查询药品列表
     */
    @Anonymous
    @ApiOperation("查询药品列表")
    @ApiImplicitParam(name = "keyword", value = "关键子", required = true, dataType = "String",
        dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('business:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "keyword",required = false) String keyword) {
        BusShop busShop =new BusShop();
        if (!StringUtils.isEmpty(keyword)){
            busShop.setName(keyword);
        }
        startPage();
        List<BusShop> list = busShopService.selectBusShopList(busShop);
        return getDataTable(list);
    }

    /**
     * 导出药品列表
     */
    @ApiOperation("导出药品列表")
    @PreAuthorize("@ss.hasPermi('business:shop:export')")
    @Log(title = "药品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusShop busShop) {
        List<BusShop> list = busShopService.selectBusShopList(busShop);
        ExcelUtil<BusShop> util = new ExcelUtil<BusShop>(BusShop.class);
        util.exportExcel(response, list, "药品数据");
    }

    /**
     * 获取药品详细信息
     */
    @Anonymous
    @ApiOperation("获取药品详细信息")
    @ApiImplicitParam(name = "id", value = "商品ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('business:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(busShopService.selectBusShopById(id));
    }

    /**
     * 新增药品
     */
    @ApiOperation("新增药品")
    @PreAuthorize("@ss.hasPermi('business:shop:add')")
    @Log(title = "药品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusShop busShop) {
        return toAjax(busShopService.insertBusShop(busShop));
    }

    /**
     * 修改药品
     */
    @ApiOperation("修改药品")
    @PreAuthorize("@ss.hasPermi('business:shop:edit')")
    @Log(title = "药品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusShop busShop) {
        return toAjax(busShopService.updateBusShop(busShop));
    }

    /**
     * 删除药品
     */
    @ApiOperation("删除药品")
    @PreAuthorize("@ss.hasPermi('business:shop:remove')")
    @Log(title = "药品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(busShopService.deleteBusShopByIds(ids));
    }
}
